<template>

  <div>

    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/admin/orderLog">订单管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>订单日志列表</el-breadcrumb-item>
    </el-breadcrumb>

    <h3 style="margin: 20px 0;">订单日志列表</h3>

    <el-table :data="tbOrderLogListData" border style="width: 100%">
      <el-table-column prop="orderLogId" label="订单日志ID" width="100px" align="center"></el-table-column>
      <el-table-column prop="orderId" label="订单ID" width="150" align="center"></el-table-column>
      <el-table-column prop="orderStatus" label="订单状态" width="100px" align="center"></el-table-column>
      <el-table-column prop="logContent" label="操作日志" header-align="center"></el-table-column>


      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-edit" size="mini" type="primary"
                     @click="handleEdit(scope.$index,scope.row) "></el-button>
          <el-dialog
              title="编辑订单列表"
              :visible.sync="dialogVisible"
              width="50%"
              :before-close="handleClose">
            <div style="margin: 20px"></div>
            <el-form :label-position="labelPosition"  label-width="80px" :model="formOrderLog">
              <el-form-item label="订单日志ID" >
                <el-input v-model="formOrderLog.orderLogId" :disabled="true" ></el-input>
              </el-form-item>

              <el-form-item label="订单ID"  >
                <el-input v-model="formOrderLog.orderId"></el-input>
              </el-form-item>

              <el-form-item label="订单状态" >
                <el-input v-model="formOrderLog.orderStatus"></el-input>
              </el-form-item>

              <el-form-item label="操作日志" >
                <el-input v-model="formOrderLog.logContent"></el-input>
              </el-form-item>



            </el-form>

            <span slot="footer" class="dialog-footer">

              <el-button type="primary" @click="confirm">确定修改</el-button>
              <el-button @click="dialogVisible = false">取消修改</el-button>
            </span>

          </el-dialog>



          <el-button circle icon="el-icon-delete" size="mini" type="danger"
                     @click="openDeleteConfirm(scope.row.orderLogId)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
export default {
  data() {
    return {
      tbOrderLogListData: [],
      dialogVisible:false,
      labelPosition:'right',
      formOrderLog:{
        orderLogId: '',
        orderId: '',
        orderStatus: '',
        logContent:'',
      }
    }
  },
  methods: {
    openDeleteConfirm(orderLogId) {
      this.$confirm('此操作将永久删除该订单日志, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(orderLogId);
      }).catch(() => {
      });
    },
    handleEdit(index,row) {
      this.orderLogIdIndex = index;
      console.log(row.orderLogId)
      this.formOrderLog = {
        orderLogId: row.orderLogId,
        orderId: row.orderId,
        orderStatus: row.orderStatus,
        logContent:row.logContent,
      };
      this.dialogVisible = true;
    },

    confirm(){
      console.log(this.formOrderLog.orderLogId)
      console.log(this.formOrderLog.orderId)
      console.log(this.formOrderLog.orderStatus)
      console.log(this.formOrderLog.logContent)
      var that = this
      let url = 'http://localhost:8888/tbOrderLogs/update-by-orderLogId';
      this.axios.post(url,this.formOrderLog).then((response) => {
        let json = response.data;
        if (json.code == 2000){
          this.$message({
            message:'修改订单日志成功！',
            type:'success'
          });
          that.loadOrderLogs()
          this.dialogVisible = false;
        }else {
          this.$message.error(response.data.message)
        }
      })
    },

    handleClose(done){
      this.$confirm('确认关闭？')
          .then(_=>{
            done();
          }).catch(_=> {});
    },



    handleDelete(orderLogId) {
      console.log('将删除orderLogId=' + orderLogId + "的订单数据……");
      let url = 'http://localhost:8888/tbOrderLogs/'+orderLogId+'/delete';
      this.axios
          // .create({headers: {'Authorization': localStorage.getItem('jwt')}})
          .post(url).then((response) => {
        let json = response.data;
        if (json.code == 2000) {
          this.$message({
            message: '删除订单日志成功！',
            type: 'success'
          });
        } else {
          this.$message.error(response.data.message);
        }
        this.loadOrderLogs();
      })
    },
    handleChangeEnable(i, orderLogId, toState) {
      let enableText = ['禁用', '启用'];
      let originState = (toState + 1) % 2;
      this.$message.error('尝试将orderLogId=' + orderLogId + '的品牌状态从【' + enableText[originState] + '】改为【' + enableText[toState] + '】，但是，此功能尚未实现！');
      setTimeout(() => {
        this.tbOrderLogListData[i].enable = originState;
      }, 200);
    },
    loadOrderLogs: function () {
      console.log('loadOrderLogs()');
      let url = 'http://localhost:8888/tbOrderLogs/list';
      console.log('url = ' + url);
      this.axios
          // .create({headers: {'Authorization': localStorage.getItem('jwt')}})
          .get(url).then((response) => {
        let json = response.data;
        if (json.code == 2000) {
          // let list = json.data;
          // for (let i = 0; i < list.length; i++) {
          //   console.log(list[i]);
          // }
          this.tbOrderLogListData = json.data;
        } else {
          this.$message.error(response.data.message);
        }
      });
    }
  },
  created() {
    // created >>> 已创建，将在mounted、显示页面之前执行
    console.log('vue created');
  },
  mounted() {
    // mounted >>> 已挂载，将在created之后、显示页面之前执行
    console.log('vue mounted');
    this.loadOrderLogs();
  }
}
</script>

<style scoped>

</style>
